package com.hzhr.iot.cqgas.ds.controller;

import com.hzhr.iot.core.util.HzhrDateUtil;
import com.hzhr.iot.cqgas.ds.dao.device.example.DevCollectDeviceDao;
import com.hzhr.iot.cqgas.ds.entity.device.DevCollectDeviceEntity;
import com.hzhr.iot.cqgas.ds.entity.device.DevCollectDeviceExample;
import com.hzhr.iot.cqgas.ds.service.CollectDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CollectDeviceController {
    @Autowired
    CollectDeviceService collectDeviceService;
    @Autowired
    DevCollectDeviceDao devCollectDeviceDao;

    @RequestMapping(value = "/syncCollectDevice")
    public void syncCollectDevice() {
        DevCollectDeviceEntity devCollectDeviceEntity = new DevCollectDeviceEntity();
        devCollectDeviceEntity.setState("3");
        DevCollectDeviceExample devCollectDeviceExample = new DevCollectDeviceExample();
        devCollectDeviceExample.createCriteria().andOutIdIsNotNull().andCategoryCodeNotEqualTo("7").andCategoryCodeNotEqualTo("8");
        devCollectDeviceDao.updateByExampleSelective(devCollectDeviceEntity, devCollectDeviceExample);

        collectDeviceService.syncCollectDevice(null, null);

        devCollectDeviceExample = new DevCollectDeviceExample();
        devCollectDeviceExample.createCriteria().andStateEqualTo("3");
        devCollectDeviceDao.deleteByExample(devCollectDeviceExample);
    }

    @RequestMapping(value = "/syncCollectDevice_day")
    public void syncCollectDevice_day() {
        DevCollectDeviceEntity devCollectDeviceEntity = new DevCollectDeviceEntity();
        devCollectDeviceEntity.setState("3");
        DevCollectDeviceExample devCollectDeviceExample = new DevCollectDeviceExample();
        devCollectDeviceExample.createCriteria().andOutIdIsNotNull().andCategoryCodeNotEqualTo("7").andCategoryCodeNotEqualTo("8");
        devCollectDeviceDao.updateByExampleSelective(devCollectDeviceEntity, devCollectDeviceExample);

        collectDeviceService.syncCollectDevice(HzhrDateUtil.getDayBegin(), null);

        devCollectDeviceExample = new DevCollectDeviceExample();
        devCollectDeviceExample.createCriteria().andStateEqualTo("3");
        devCollectDeviceDao.deleteByExample(devCollectDeviceExample);
    }

    @RequestMapping(value = "/syncCollectDeviceStatusInfo")
    public void syncCollectDeviceStatusInfo() {
        collectDeviceService.syncCollectDeviceStatusInfo();
    }
}
